<template>
  <div class="menu-list">
    <div
      class="menu-item"
      :class="activeMenu == index ? 'activeMenu' : ''"
      v-for="(item, index) in menuList"
      :key="index"
      @click="changeMenu(item, index)"
    >
      <i class="iconfont" :class="item.icon"></i>
      <span>{{ item.text }}</span>
    </div>
    <div
      v-if="activeMenu >= 0"
      class="active-shu"
      :class="activeMenu >= 0 ? 'activeMenu' + activeMenu : ''"
    ></div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    setActiveMenu: {
      type: String,
      defalut: "",
    },
  },
  data() {
    return {
      activeMenu: -1,
      menuList: [
        {
          icon: "icon-zuocecaidan-mokuai",
          text: "模块",
          type: "module",
          comName: "module",
        },
        {
          icon: "icon-zuocecaidan-yemian",
          text: "页面",
          type: "page",
        },
        {
          icon: "icon-zuocecaidan-kongjian",
          text: "控件",
          type: "widget",
        },
        {
          icon: "icon-zuocecaidan-moban",
          text: "模板",
          type: "template",
        },
      ],
    };
  },
  watch: {
    setActiveMenu(val) {
      if (!val) return;
      let index = this.menuList.findIndex((d) => {
        return d.type == val;
      });
      console.log(val, index);
      this.activeMenu = index;
      this.$emit("changeMenu", { menu: this.menuList[index] });
    },
  },
  computed: {},
  methods: {
    changeMenu(item, index) {
      this.activeMenu = index;
      this.$emit("changeMenu", { menu: item });
    },
  },
};
</script>

<style lang="scss" scoped>
.menu-list {
  width: 100%;
  position: relative;
  .menu-item {
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;

    .iconfont {
      font-size: 24px;
    }

    span {
      font-size: 12px;
      font-weight: 400;
      line-height: 17px;
      color: #8c8c8c;
    }
  }
  .activeMenu {
    position: relative;
    .iconfont {
      color: #1890fc;
    }
    span {
      color: #1890fc;
    }
  }

  .active-shu {
    width: 4px;
    height: 40px;
    position: absolute;
    left: 0;
    top: 24px;
    z-index: 11;
    background: #1890fc;
    transition: all 0.3s;
  }

  .activeMenu0 {
    top: 24px;
  }
  .activeMenu1 {
    top: 91px;
  }
  .activeMenu2 {
    top: 160px;
  }
  .activeMenu3 {
    top: 229px;
  }
}
</style>
